/*
 * Copyright (c) 2019 - 2020 IoT Company of Midea Group.
 *
 * File Name 	    : 
 * Description	    : HAL adaptor
 *
 * Version	        : v0.1
 * Author			: 
 * Date	            : 2019/09/15  refactoring
 * History	        : 
 */

#ifndef __MS_HAL_UART_H__
#define	__MS_HAL_UART_H__

#include "stdint.h"
#include "ms_hal.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum
{
    MS_HAL_UART_LOG_OFF = 0,
    MS_HAL_UART_LOG_ON
} ms_hal_uart_log_state_t;

/**
 * @brief init uart
 * @param[in] baud_rate: default option 9600bit/s 
 * @return if successly, return MS_HAL_RESULT_SUCCESS, \n
 *         otherwise return MS_HAL_RESULT_ERROR
 */
ms_hal_result_t ms_hal_uart_init(uint32_t baud_rate);

/**
 * @brief stop uart
 * @note you need to init uart pin as gpio
 * @return if successly, return MS_HAL_RESULT_SUCCESS, \n
 *         otherwise return MS_HAL_RESULT_ERROR
 */
ms_hal_result_t ms_hal_uart_stop(void);

/**
 * @brief write data to uart
 * @param[in] buffer : store the write data
 * @param[in] len : write data length
 * @return if successly, return MS_HAL_RESULT_SUCCESS, \n
 *         otherwise return MS_HAL_RESULT_ERROR
 */
ms_hal_result_t ms_hal_uart_write(uint8_t *buffer, uint32_t len);

/**
 * @brief read data from uart
 * @param[out] buffer : the data will store in this buffer
 * @param[in] len : buffer size
 * @param[in] timeout_ms : read data length
 * @return actually read data bytes
 */
uint32_t ms_hal_uart_read(uint8_t *buffer, uint32_t len, uint32_t timeout_ms);

/**
 * @brief turn on/off log output
 * @param[in] state: use ms_hal_uart_log_state_t
 */
void ms_hal_uart_set_log_output(ms_hal_uart_log_state_t state);

#ifdef __cplusplus
}
#endif

#endif

